package com.kanesoft.android.gdx.actors.fight;

import java.util.Iterator;
import java.util.Vector;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;

public final class ControlActorFight implements InputProcessor {

    private Vector<InputProcessor> inputProcessorList;

    public ControlActorFight() {
        Gdx.input.setInputProcessor(this);
        inputProcessorList = new Vector<InputProcessor>();
    }

    public void addInputProcessor(InputProcessor inputHandler) {
        if (inputHandler == null) return;

        inputProcessorList.add(inputHandler);
    }

    @Override
    public boolean keyDown(int keycode) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.keyDown(keycode);
        }
        return false;
    }

    @Override
    public boolean keyUp(int keycode) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.keyUp(keycode);
        }
        return false;
    }

    @Override
    public boolean keyTyped(char character) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.keyTyped(character);
        }
        return false;
    }

    @Override
    public boolean touchDown(int x, int y, int pointer, int button) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.touchDown(x, y, pointer, button);
        }
        return false;
    }

    @Override
    public boolean touchUp(int x, int y, int pointer, int button) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.touchUp(x, y, pointer, button);
        }
        return false;
    }

    @Override
    public boolean touchDragged(int x, int y, int pointer) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.touchDragged(x, y, pointer);
        }
        return false;
    }

    @Override
    public boolean touchMoved(int x, int y) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.touchMoved(x, y);
        }
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        for (Iterator<InputProcessor> iterator = inputProcessorList.iterator(); iterator.hasNext();) {
            InputProcessor inputProcessor = (InputProcessor) iterator.next();
            inputProcessor.scrolled(amount);
        }
        return false;
    }

}
